home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / SSDrawStyle.as < prev    next >
Text File  |  2006-11-29  |  15KB  |  375 lines

  1. class SSDrawStyle extends SSDrawing
  2. {
  3.    var offsetX = 0;
  4.    var offsetY = 0;
  5.    var mainFillLayer = 20;
  6.    var store = false;
  7.    var types = {fillTexture:"string",fillColor:"hex",viewSlope:"vector",lightDirection:"vector"};
  8.    var defaultType = "number";
  9.    var caseSensitive = true;
  10.    var capEnd = true;
  11.    var className = "SSDrawStyle";
  12.    var editor_drawStyle = true;
  13.    static var editor_ignore = true;
  14.    function SSDrawStyle()
  15.    {
  16.       super();
  17.    }
  18.    function setup()
  19.    {
  20.       this.viewSlope = SSGlobal.DRAW_VIEW_DIRECTION;
  21.       this.surfaceEdge = new SSMaterial();
  22.       this.wallEdge = new SSMaterial();
  23.       this.emptyEdge = new SSMaterial();
  24.    }
  25.    function define()
  26.    {
  27.    }
  28.    function applyNodeToObject(obj, node)
  29.    {
  30.       var _loc3_ = node.attributes;
  31.       var _loc1_ = undefined;
  32.       var _loc4_ = undefined;
  33.       for(var _loc5_ in _loc3_)
  34.       {
  35.          if((_loc4_ = obj.types[_loc5_]) == null)
  36.          {
  37.             _loc4_ = obj.defaultType;
  38.          }
  39.          switch(_loc4_)
  40.          {
  41.             case "hex":
  42.                _loc1_ = GDK.Tools.hexToNumber(_loc3_[_loc5_]);
  43.                if(!isNaN(_loc1_))
  44.                {
  45.                   obj[_loc5_] = _loc1_;
  46.                }
  47.                break;
  48.             case "number":
  49.                _loc1_ = Number(_loc3_[_loc5_]);
  50.                if(!isNaN(_loc1_))
  51.                {
  52.                   obj[_loc5_] = _loc1_;
  53.                }
  54.                break;
  55.             case "string":
  56.                _loc1_ = _loc3_[_loc5_];
  57.                if(_loc1_.length > 0)
  58.                {
  59.                   obj[_loc5_] = _loc1_;
  60.                }
  61.                break;
  62.             case "vector":
  63.                _loc1_ = _loc3_[_loc5_].split(",");
  64.                _loc1_ = new Vector(Number(_loc1_[0]),Number(_loc1_[1]),Number(_loc1_[2]));
  65.                if(_loc1_.length != NaN)
  66.                {
  67.                   obj[_loc5_] = _loc1_;
  68.                }
  69.          }
  70.       }
  71.    }
  72.    function defineFromXML()
  73.    {
  74.       if(this.styleXML == null)
  75.       {
  76.          return undefined;
  77.       }
  78.       this.applyNodeToObject(this,this.styleXML);
  79.       var _loc4_ = undefined;
  80.       var _loc2_ = undefined;
  81.       var _loc5_ = undefined;
  82.       var _loc3_ = _loc5_ = this.styleXML.childNodes.length;
  83.       while((_loc3_ = _loc3_ - 1) > -1)
  84.       {
  85.          if(_loc4_ = this[_loc2_ = _loc5_[_loc3_].nodeName + "Edge"])
  86.          {
  87.             this.applyNodeToObject(_loc4_,_loc2_);
  88.          }
  89.       }
  90.       delete this.styleXML;
  91.    }
  92.    function prepare()
  93.    {
  94.       this.viewSlope.normalize();
  95.       this.lightDirection.normalize();
  96.       this.surfaceEdge.prepare();
  97.       this.wallEdge.prepare();
  98.       this.emptyEdge.prepare();
  99.    }
  100.    function process()
  101.    {
  102.       this.capEnd = this.viewSlope.x >= 0 ? 1 : (this.viewSlope != 0 ? -1 : 0);
  103.       this.viewAngle = Math.atan2(- this.viewSlope.x,this.viewSlope.y) * 57.2957795;
  104.       this.mainFill(this.points);
  105.       var _loc2_ = this.groups.length;
  106.       while((_loc2_ = _loc2_ - 1) > -1)
  107.       {
  108.          this.groupFill(this.groups[_loc2_],this.groups[_loc2_].mask);
  109.       }
  110.    }
  111.    function mainFill(points)
  112.    {
  113.       this.setLayer(this.mainFillLayer);
  114.       if(this.fillTexture != null)
  115.       {
  116.          this.bitmapShape(this.fillTexture,points);
  117.       }
  118.       else if(this.fillColor != null)
  119.       {
  120.          this.setLayer(this.mainFillLayer);
  121.          this.solidShape(this.fillColor,points);
  122.       }
  123.       this.transform(this.offsetX,this.offsetY);
  124.    }
  125.    function pickStyle(mask)
  126.    {
  127.       if(mask & 1)
  128.       {
  129.          if(mask & 2)
  130.          {
  131.             return this.surfaceEdge;
  132.          }
  133.          return this.wallEdge;
  134.       }
  135.       return this.emptyEdge;
  136.    }
  137.    function createSegment(point, normal, edge, material, scale)
  138.    {
  139.       if(scale == null)
  140.       {
  141.          scale = 1;
  142.       }
  143.       var _loc7_ = this.viewSlope.x;
  144.       var _loc6_ = this.viewSlope.y;
  145.       var _loc3_ = point;
  146.       var _loc8_ = material.rearDepth <= 0 ? _loc3_ : new Vector(_loc3_.x - material.rearDepth * _loc7_,_loc3_.y - material.rearDepth * _loc6_,0);
  147.       var _loc9_ = material.frontDepth <= 0 ? _loc3_ : new Vector(_loc3_.x + material.frontDepth * _loc7_,_loc3_.y + material.frontDepth * _loc6_,0);
  148.       var _loc11_ = normal.dot(edge.normal);
  149.       if(material.thickness > 0)
  150.       {
  151.          var _loc13_ = material.thickness;
  152.          var _loc5_ = _loc13_ / _loc11_;
  153.          var _loc10_ = new Vector(_loc9_.x - normal.x * _loc5_ + material.sideExtrude * _loc7_,_loc9_.y - normal.y * _loc5_ + material.sideExtrude * _loc6_,0);
  154.          var _loc15_ = new Vector(_loc8_.x - normal.x * _loc5_ - material.sideExtrude * _loc7_,_loc8_.y - normal.y * _loc5_ - material.sideExtrude * _loc6_,0);
  155.          var _loc16_ = new Vector(_loc3_.x - normal.x * _loc5_,_loc3_.y - normal.y * _loc5_,0);
  156.       }
  157.       else
  158.       {
  159.          _loc10_ = _loc9_;
  160.          _loc15_ = _loc8_;
  161.          _loc16_;
  162.       }
  163.       var _loc14_ = !material.bottomDepth ? _loc10_ : new Vector(_loc10_.x - material.bottomDepth * _loc7_,_loc10_.y - material.bottomDepth * _loc6_,0);
  164.       var _loc12_ = [_loc8_,_loc3_,_loc9_,_loc10_,_loc14_,_loc16_,_loc15_];
  165.       (_loc12_.normal = new Vector(normal.x * _loc11_,normal.y * _loc11_,0)).normalize();
  166.       return _loc12_;
  167.    }
  168.    function groupFill(edges, mask)
  169.    {
  170.       var _loc3_ = edges[0].attributes;
  171.       if(_loc3_ == null)
  172.       {
  173.          return undefined;
  174.       }
  175.       var _loc17_ = new SSDrawing();
  176.       var _loc34_ = new SSDrawing();
  177.       var _loc35_ = new SSDrawing();
  178.       var _loc38_ = new SSDrawing();
  179.       var _loc40_ = edges[0].previous == edges[edges.length];
  180.       var _loc18_ = edges.length;
  181.       var _loc24_ = [];
  182.       var _loc2_ = undefined;
  183.       var _loc4_ = undefined;
  184.       var _loc7_ = _loc3_.ambientColor;
  185.       var _loc6_ = _loc3_.diffuseColor;
  186.       var _loc8_ = _loc3_.specularColor;
  187.       if(_loc40_)
  188.       {
  189.          _loc24_[_loc18_] = _loc24_[0] = this.createSegment(edges[0].a,edges[0].a.normal,edges[0],_loc3_);
  190.       }
  191.       else
  192.       {
  193.          switch(_loc3_.endAlign)
  194.          {
  195.             case 0:
  196.             default:
  197.                _loc24_[0] = _loc0_ = this.createSegment(edges[0].a,edges[0].normal,edges[0],_loc3_);
  198.                _loc2_ = _loc0_;
  199.                _loc24_[_loc18_] = _loc0_ = this.createSegment(edges[_loc18_ - 1].b,edges[_loc18_ - 1].normal,edges[_loc18_ - 1],_loc3_);
  200.                _loc4_ = _loc0_;
  201.                break;
  202.             case 1:
  203.                _loc24_[0] = _loc0_ = this.createSegment(edges[0].a,edges[0].a.normal,edges[0],_loc3_);
  204.                _loc2_ = _loc0_;
  205.                _loc24_[_loc18_] = _loc0_ = this.createSegment(edges[_loc18_ - 1].b,edges[_loc18_ - 1].b.normal,edges[_loc18_ - 1],_loc3_);
  206.                _loc4_ = _loc0_;
  207.                break;
  208.             case 2:
  209.                _loc24_[0] = _loc0_ = this.createSegment(edges[0].a,edges[0].previous.direction,edges[0],_loc3_);
  210.                _loc2_ = _loc0_;
  211.                _loc24_[_loc18_] = _loc0_ = this.createSegment(edges[_loc18_ - 1].b,edges[_loc18_ - 1].next.direction,edges[_loc18_ - 1],_loc3_);
  212.                _loc4_ = _loc0_;
  213.          }
  214.          if(_loc3_.capSurface && _loc3_.thickness > 0)
  215.          {
  216.             var _loc16_ = _loc2_.normal.cross(Vector.VECNZ);
  217.             if(this.viewSlope.dot(_loc16_) < 0)
  218.             {
  219.                var _loc11_ = this.calculateLighting(_loc16_,_loc7_,_loc6_,_loc8_).valueOf();
  220.                _loc17_.solidShape(_loc11_,[_loc2_[1],_loc2_[2],_loc2_[3],_loc2_[5]]);
  221.                _loc34_.solidShape(_loc11_,[_loc2_[0],_loc2_[1],_loc2_[5],_loc2_[6]]);
  222.             }
  223.             _loc16_ = _loc4_.normal.cross(Vector.VECNZ);
  224.             if(this.viewSlope.dot(_loc16_) < 0)
  225.             {
  226.                _loc11_ = this.calculateLighting(_loc16_,_loc7_,_loc6_,_loc8_).valueOf();
  227.                _loc17_.solidShape(_loc11_,[_loc4_[1],_loc4_[2],_loc4_[3],_loc4_[5]]);
  228.                _loc34_.solidShape(_loc11_,[_loc4_[0],_loc4_[1],_loc4_[5],_loc4_[6]]);
  229.             }
  230.          }
  231.       }
  232.       while(_loc18_ = _loc18_ - 1)
  233.       {
  234.          _loc24_[_loc18_] = this.createSegment(edges[_loc18_].a,edges[_loc18_].a.normal,edges[_loc18_],_loc3_);
  235.       }
  236.       var _loc36_ = !SSMaterial.TEXTURES_ENABLED ? null : _loc3_.surfaceTexture;
  237.       var _loc43_ = _loc3_.surfaceTextureMode;
  238.       var _loc19_ = _loc3_.sideExtrude;
  239.       var _loc20_ = _loc3_.smoothing;
  240.       var _loc42_ = 1 - _loc20_;
  241.       var _loc41_ = this.viewSlope.x * 180;
  242.       var _loc28_ = _loc3_.ratios;
  243.       var _loc25_ = _loc3_.alphas;
  244.       var _loc39_ = _loc3_.frontDepth + _loc3_.rearDepth;
  245.       var _loc37_ = undefined;
  246.       _loc18_ = edges.length;
  247.       _loc4_ = _loc24_[_loc18_];
  248.       var _loc5_ = undefined;
  249.       var _loc21_ = undefined;
  250.       var _loc26_ = edges[_loc18_ - 1].b;
  251.       var _loc13_ = undefined;
  252.       var _loc22_ = undefined;
  253.       var _loc27_ = _loc4_.normal;
  254.       var _loc32_ = undefined;
  255.       var _loc10_ = undefined;
  256.       var _loc14_ = undefined;
  257.       if(!_loc19_)
  258.       {
  259.          _loc14_ = this.calculateLighting(Vector.VECPZ,_loc7_,_loc6_,_loc8_).valueOf();
  260.       }
  261.       while((_loc18_ = _loc18_ - 1) > -1)
  262.       {
  263.          _loc21_ = edges[_loc18_].a;
  264.          _loc2_ = _loc24_[_loc18_];
  265.          _loc13_ = _loc5_ = edges[_loc18_].normal;
  266.          _loc22_ = _loc2_.normal;
  267.          if((_loc37_ = this.viewSlope.dot(_loc5_.normal) < 0) && _loc39_ > 0)
  268.          {
  269.             if(_loc36_ != null)
  270.             {
  271.                _loc17_.textureStrip(_loc36_,_loc2_[_loc3_.surfaceTexturePoint],_loc4_[_loc3_.surfaceTexturePoint],_loc3_.surfaceTextureMode,this.viewAngle);
  272.             }
  273.             else if(_loc20_ != 0)
  274.             {
  275.                if(_loc20_ == 1)
  276.                {
  277.                   _loc11_ = this.calculateLighting(_loc22_,_loc7_,_loc6_,_loc8_).valueOf();
  278.                   _loc10_ = this.calculateLighting(_loc27_,_loc7_,_loc6_,_loc8_).valueOf();
  279.                }
  280.                else
  281.                {
  282.                   _loc11_ = this.calculateLighting(this.smoothNormal(_loc13_,_loc22_,_loc20_),_loc7_,_loc6_,_loc8_).valueOf();
  283.                   _loc10_ = this.calculateLighting(this.smoothNormal(_loc13_,_loc27_,_loc20_),_loc7_,_loc6_,_loc8_).valueOf();
  284.                }
  285.                switch(_loc3_.smoothingQuality)
  286.                {
  287.                   case 0:
  288.                   default:
  289.                      _loc32_ = [_loc11_,_loc10_];
  290.                      break;
  291.                   case 1:
  292.                      _loc32_ = [_loc11_,this.calculateLighting(_loc13_,_loc7_,_loc6_,_loc8_).valueOf(),_loc10_];
  293.                      break;
  294.                   case 2:
  295.                      var _loc23_ = this.calculateLighting(_loc13_,_loc7_,_loc6_,_loc8_).valueOf();
  296.                      _loc32_ = [_loc11_,_loc23_,_loc23_,_loc10_];
  297.                }
  298.                var _loc15_ = _loc5_.length;
  299.                var _loc33_ = new GradientMatrix(_loc5_.center.x,_loc5_.center.y,_loc15_,_loc15_,this.viewSlope.x * _loc15_ * 0.5,0);
  300.                _loc17_.gradientShape("linear",_loc32_,_loc25_,_loc28_,_loc33_,[_loc2_[1],_loc2_[2],_loc4_[2],_loc4_[1]]);
  301.                _loc34_.gradientShape("linear",_loc32_,_loc25_,_loc28_,_loc33_,[_loc2_[0],_loc2_[1],_loc4_[1],_loc4_[0]]);
  302.             }
  303.             else
  304.             {
  305.                var _loc29_ = this.calculateLighting(_loc13_,_loc7_,_loc6_,_loc8_).valueOf();
  306.                _loc17_.solidShape(_loc29_,[_loc2_[1],_loc2_[2],_loc4_[2],_loc4_[1]]);
  307.                _loc34_.solidShape(_loc29_,[_loc2_[0],_loc2_[1],_loc4_[1],_loc4_[0]]);
  308.             }
  309.          }
  310.          else if(!_loc37_ && _loc3_.bottomDepth)
  311.          {
  312.             _loc29_ = this.calculateLighting(_loc13_.getReversed(),_loc7_,_loc6_,_loc8_).valueOf();
  313.             _loc38_.solidShape(_loc29_,[_loc2_[3],_loc2_[4],_loc4_[4],_loc4_[3]]);
  314.          }
  315.          if(_loc19_ && _loc3_.thickness > 0)
  316.          {
  317.             var _loc12_ = _loc3_.thickness;
  318.             (_loc16_ = new Vector((- _loc5_.normal.x) * _loc12_,(- _loc5_.normal.y) * _loc12_,- _loc19_).cross(_loc5_.direction)).normalize();
  319.             _loc14_ = this.calculateLighting(_loc16_,_loc7_,_loc6_,_loc8_).valueOf();
  320.             if(_loc3_.sideSmoothing)
  321.             {
  322.                var _loc31_ = undefined;
  323.                var _loc30_ = undefined;
  324.                (_loc31_ = new Vector((- _loc21_.normal.x) * _loc12_,(- _loc21_.normal.y) * _loc12_,- _loc19_).cross(_loc5_.direction)).normalize();
  325.                (_loc30_ = new Vector((- _loc26_.normal.x) * _loc12_,(- _loc26_.normal.y) * _loc12_,- _loc19_).cross(_loc5_.direction)).normalize();
  326.                _loc11_ = this.calculateLighting(this.smoothNormal(_loc16_,_loc31_,_loc3_.sideSmoothing),_loc7_,_loc6_,_loc8_).valueOf();
  327.                _loc10_ = this.calculateLighting(this.smoothNormal(_loc16_,_loc30_,_loc3_.sideSmoothing),_loc7_,_loc6_,_loc8_).valueOf();
  328.                _loc33_ = new GradientMatrix((_loc2_[2].x + _loc4_[3].x) / 2,(_loc2_[2].y + _loc4_[3].y) / 2,_loc5_.length,_loc5_.length,this.viewSlope.x * _loc15_ * 0.5,0);
  329.                switch(_loc3_.smoothingQuality)
  330.                {
  331.                   case 0:
  332.                   default:
  333.                      _loc32_ = [_loc11_,_loc10_];
  334.                      break;
  335.                   case 1:
  336.                      _loc32_ = [_loc11_,_loc14_,_loc10_];
  337.                      break;
  338.                   case 2:
  339.                      _loc32_ = [_loc11_,_loc14_,_loc14_,_loc10_];
  340.                }
  341.                _loc17_.gradientShape("linear",_loc32_,_loc25_,_loc28_,_loc33_,[_loc2_[2],_loc2_[3],_loc4_[3],_loc4_[2]]);
  342.             }
  343.             else
  344.             {
  345.                _loc35_.solidShape(_loc14_,[_loc2_[2],_loc2_[3],_loc4_[3],_loc4_[2]]);
  346.             }
  347.          }
  348.          else
  349.          {
  350.             _loc35_.solidShape(_loc14_,[_loc2_[2],_loc2_[3],_loc4_[3],_loc4_[2]]);
  351.          }
  352.          if(_loc3_.sideTexture != null)
  353.          {
  354.             this.setLayer(_loc3_.sideTextureLayer);
  355.             this.assetStrip(_loc3_.sideTexture,_loc2_[_loc3_.sideTexturePoint],_loc4_[_loc3_.sideTexturePoint],_loc3_.sideTextureMode,_loc3_.sideTextureAlign,true);
  356.          }
  357.          _loc26_ = _loc21_;
  358.          _loc27_ = _loc22_;
  359.          _loc4_ = _loc2_;
  360.       }
  361.       this.setLayer(_loc3_.bottomSurfaceLayer);
  362.       this.inst.push.apply(this.inst,_loc38_.inst);
  363.       this.setLayer(_loc3_.frontSurfaceLayer);
  364.       this.inst.push.apply(this.inst,_loc17_.inst);
  365.       this.setLayer(_loc3_.sideSurfaceLayer);
  366.       this.inst.push.apply(this.inst,_loc35_.inst);
  367.       this.setLayer(_loc3_.rearSurfaceLayer);
  368.       this.inst.push.apply(this.inst,_loc34_.inst);
  369.    }
  370.    function smoothNormal(a, b, i)
  371.    {
  372.       return new Vector(a.x * (1 - i) + b.x * i,a.y * i + b.y * i,0).normalize();
  373.    }
  374. }
  375.